<template>
	<view>
		<my-address></my-address>
		<view class="cart-title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text class="cart-title-text">购物车</text>
		</view>
		<uni-swipe-action v-show='cart.length'>
			<block v-for="item in cart" :key="item.goods_id">
				<uni-swipe-action-item :right-options='options' @click="swipeItemClickHandler(item.goods_id)">
					<my-goods :goods="item" showNum show-radio @radio-change="radioChangeHandler" @numberChange="numberChangeHandler"></my-goods>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		<my-empty v-show='!cart.length' text="购物车竟然是空的"></my-empty>
		<my-settle></my-settle>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabber-badge.js'
	import { mapState, mapMutations } from 'vuex'
	export default {
		mixins: [badgeMix],
		computed:{
			...mapState('m_cart', ['cart'])
		},
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#C00000'
					}
				}]
			}
		},
		onLoad(){},
		methods: {
			...mapMutations('m_cart',['updateGoodsState','updateGoodsCount','removeGoodsById']),
			radioChangeHandler(e){
				this.updateGoodsState(e)
			},
			numberChangeHandler(e){
				this.updateGoodsCount(e)
			},
			swipeItemClickHandler(goodsId){
				this.removeGoodsById(goodsId)
			}
		}
	}
</script>

<style lang="scss">
.cart-title{
	height: 40px;
	display: flex;
	align-items: center;
	font-size: 14px;
	padding-left: 5px;
	border-bottom: 1px solid #efefef;
	.cart-title-text{
		margin-left: 10px;
	}
}
</style>
